<template>
  <div style="margin-top: 16px">
    <el-form label-width="80px" size="small" >
<!--      <el-form-item label="消息实例">-->
<!--          <el-select v-model="bindMessageId" @change="updateTaskMessage">-->
<!--            <el-option v-for="id in Object.keys(messageMap)" :value="id" :label="messageMap[id]" :key="id" />-->
<!--          </el-select>-->
<!--      </el-form-item>-->
      <el-empty description="接收任务无配置内容"/>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "ReceiveTaskPanel",
  props: {
    id: {
      type: String,
      required: true
    },
  },
  data() {
    return {
      bindMessageId: "",
      messageMap: {},
    };
  },
  watch: {
    id: {
      immediate: true,
      handler() {
        // this.$nextTick(() => this.getBindMessage());
      }
    }
  },
  created() {
    // this.bpmnMessageRefsMap = Object.create(null);
    // this.bpmnRootElements = this.modelerStore.modeler.getDefinitions().rootElements;
    // this.bpmnRootElements
    //   .filter(el => el.$type === "bpmn:Message")
    //   .forEach(m => {
    //     this.bpmnMessageRefsMap[m.id] = m;
    //     this.$set(this.messageMap, m.id, m.name);
    //   });
    // this.$set(this.messageMap, "-1", "无"); // 添加一个空对象，保证可以取消原消息绑定
  },
  methods: {
    getBindMessage() {
      this.bpmnElement = this.modelerStore.element;
      this.bindMessageId = this.modelerStore.element.businessObject?.messageRef?.id || "-1";
      this.deleteElementFormExtensions();
    },
    updateTaskMessage(messageId) {
      if (messageId === "-1") {
        this.modelerStore.modeling.updateProperties(this.bpmnElement, {
          messageRef: null
        });
      } else {
        this.modelerStore.modeling.updateProperties(this.bpmnElement, {
          messageRef: this.bpmnMessageRefsMap[messageId]
        });
      }
    },

    // 新建节点时,默认是用户节点,会添加表单相关扩展属性,当前任务直接删除掉
    deleteElementFormExtensions() {
      const element = this.modelerStore.element;
      if (element.businessObject?.extensionElements?.values) {
        element.businessObject.extensionElements.values =
          element.businessObject.extensionElements.values.filter(ex => ex.$type !== 'flowable:FormItems');
      }
    }

  },
  beforeDestroy() {
    this.bpmnElement = null;
  }
};
</script>
